/******************************************************************************
Project    : Real time rtsp server library base on live555
*******************************************************************************
File Name    :  <AdtsRTimeFramedSource.h>:  adts real time framed source head file
Module Name  :  
Description  :  None
History      :
 No.   Ver.     Date        Designed by  Comment
-----+--------+----------+------------+---------------------------------------
 001   0.00.01  05/25/2015  <3G@LIURENHUA>   <adts real time framed source head file>
*******************************************************************************/
#ifndef _ADTS_FRAMED_RTIME_SOURCE_H
#define _ADTS_FRAMED_RTIME_SOURCE_H

#include <FramedSource.hh>
#ifdef LOCAL_SOCK_INPUT
#include <LocalUdpSocket.h>
#endif /* LOCAL_SOCK_INPUT */

#include "RealTimeRtspServer_common.h"

/******************************************************************************
  macro define
 ******************************************************************************/
#define MAX_AFRAME_SIZE		(4    * 1024)

/******************************************************************************
  enum declaration
 ******************************************************************************/

/******************************************************************************
  class declaration
 ******************************************************************************/
class ADtsRTimeFramedSource : public FramedSource
{
public:
	u_int32_t samplingFrequency() const { return m_unFs; }
	u_int8_t numChannels() const { return m_ucCh; }
	char const* configStr() const { return m_cConfigStr; }
	static ADtsRTimeFramedSource* createNew(
							UsageEnvironment & env,
#ifdef LOCAL_SOCK_INPUT
							const char  *pcIdentity,
#endif /* LOCAL_SOCK_INPUT */
							const CH_CFG_et eChCfg,
							const FS_IDX_et eFsIdx,
							const PROFILE_et eProfile,
#ifdef LOCAL_SOCK_INPUT
							const u_int32_t unSBufSize,
							const u_int32_t unRBufSize
#else
							queue_t *pstQue
#endif /* LOCAL_SOCK_INPUT */
							);
	virtual unsigned int maxFrameSize() const {
		return MAX_AFRAME_SIZE;
	};
	
private:
	/* Constructor function */
	ADtsRTimeFramedSource(UsageEnvironment & env,
#ifdef LOCAL_SOCK_INPUT
							const char  *pcIdentity,
#endif /* LOCAL_SOCK_INPUT */
							const CH_CFG_et eChCfg,
							const FS_IDX_et eFsIdx,
							const PROFILE_et eProfile,
#ifdef LOCAL_SOCK_INPUT
							const u_int32_t unSBufSize,
							const u_int32_t unRBufSize
#else
							queue_t *pstQue
#endif /* LOCAL_SOCK_INPUT */
							);
	/* Destructor function */
	virtual ~ADtsRTimeFramedSource(void);
	virtual void doGetNextFrame();
	
private:
#ifdef LOCAL_SOCK_INPUT
	/* Local socket object pointer */
	LSOCK_OBJECT_st *pstServer;
#else
	queue_t *m_que;
#endif /* LOCAL_SOCK_INPUT */
	/* Microsecond each frame */
	u_int32_t m_unUsecPerFrm;
	u_int32_t m_unUsecRemain;
	u_int32_t m_unUsecLeft;
	/* Sample frequency */
	u_int32_t m_unFs;
	/* Channel number */
	u_int8_t m_ucCh;
	/* AudioSpecificConfig */
	char m_cConfigStr[5];
};
#endif /* _ADTS_FRAMED_RTIME_SOURCE_H */
